<?php

class SweetException extends Exception
{
	/**
	 * SweetException File
	 *
	 * @var string
	 */
	public $seFile;
	
	/**
	 * SweetException Function
	 *
	 * @var string
	 */
	public $seFunction;
	
	/**
	 * SweetException Line number
	 *
	 * @var int
	 */
	public $seLine;
	
	/**
	 * SweetException Message
	 *
	 * @var string
	 */
	public $seMessage;
	
	/**
	 * SweetException Line of Code
	 *
	 * @var string
	 */
	public $seCode;
	
	/**
	 * Generates the Error Text 
	 *
	 * @param string $message
	 */
	private function generateException($message)
	{
		$trace = debug_backtrace();
		$code = explode("\n",file_get_contents($trace[2]['file']));
		
		$this->seFile = $trace[2]['file'];
		$this->seFunction = $trace[2]['function'];
		$this->seLine = $trace[2]['line'];
		$this->seMessage = $message;
		$this->seCode = trim($code[$this->seLine-1]);
	}	
	
	/**
	 * Constructor
	 *
	 * @param string $message
	 */
	public function __construct($message)
	{
		$this->generateException($message);
		parent::__construct($message);
	}
	
	/**
	 * toString
	 *
	 * @return string
	 */
	public function __toString()
	{
		return $this->seFunction.": ".$this->seMessage." ".$this->seCode." ".$this->seFile." [".$this->seLine."]";		
	}
}

?>